/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.cookor.poi.modules.weixin.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.cookor.poi.common.config.Global;
import com.cookor.poi.common.persistence.Page;
import com.cookor.poi.common.web.BaseController;
import com.cookor.poi.common.utils.StringUtils;
import com.cookor.poi.modules.weixin.entity.TWeixinClinic;
import com.cookor.poi.modules.weixin.service.TWeixinClinicService;

/**
 * 诊所配置Controller
 * @author poi
 * @version 2021-03-16
 */
@Controller
@RequestMapping(value = "${adminPath}/weixin/tWeixinClinic")
public class TWeixinClinicController extends BaseController {

	@Autowired
	private TWeixinClinicService tWeixinClinicService;
	
	@ModelAttribute
	public TWeixinClinic get(@RequestParam(required=false) String id) {
		TWeixinClinic entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tWeixinClinicService.get(id);
		}
		if (entity == null){
			entity = new TWeixinClinic();
		}
		return entity;
	}
	
	@RequiresPermissions("weixin:tWeixinClinic:view")
	@RequestMapping(value = {"list", ""})
	public String list(TWeixinClinic tWeixinClinic, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TWeixinClinic> page = tWeixinClinicService.findPage(new Page<TWeixinClinic>(request, response), tWeixinClinic); 
		model.addAttribute("page", page);
		return "modules/weixin/tWeixinClinicList";
	}

	@RequiresPermissions("weixin:tWeixinClinic:view")
	@RequestMapping(value = "form")
	public String form(TWeixinClinic tWeixinClinic, Model model) {
		model.addAttribute("tWeixinClinic", tWeixinClinic);
		return "modules/weixin/tWeixinClinicForm";
	}

	@RequiresPermissions("weixin:tWeixinClinic:edit")
	@RequestMapping(value = "save")
	public String save(TWeixinClinic tWeixinClinic, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tWeixinClinic)){
			return form(tWeixinClinic, model);
		}
		tWeixinClinicService.save(tWeixinClinic);
		addMessage(redirectAttributes, "保存诊所配置成功");
		return "redirect:"+Global.getAdminPath()+"/weixin/tWeixinClinic/?repage";
	}
	
	@RequiresPermissions("weixin:tWeixinClinic:edit")
	@RequestMapping(value = "delete")
	public String delete(TWeixinClinic tWeixinClinic, RedirectAttributes redirectAttributes) {
		tWeixinClinicService.delete(tWeixinClinic);
		addMessage(redirectAttributes, "删除诊所配置成功");
		return "redirect:"+Global.getAdminPath()+"/weixin/tWeixinClinic/?repage";
	}

}